####
# solve model
@everywhere using Distributed

@everywhere println("Activating packages")
@everywhere using Pkg
@everywhere Pkg.activate("scripts/5-model")
@everywhere Pkg.instantiate()

@everywhere using CSV, LinearAlgebra, Dates, Statistics, InvertedIndices, JLD2, DataFrames, IterTools
@everywhere include("3-0-cf-functions.jl")
@everywhere include("2-0-cf-wrapper.jl")
print("Functions loaded")
tol = 5e-4
#tol = .25

####################################
###### run the base model 
####################################
options_in = []
# ramp, amenities, produc, realloc_workers, realloc_pollution, realloc_production, abatement, congestion, opt, vsl_elastic, info, heterog
# tol, θ, α, γ, ι

# MAIN RESULTS

# base model:      false, true, 0.0, true, true, true, true, false, false, false, true, false
push!(options_in, (false, true, 0.0, true, true, true, true, false, false, false, true, false, tol))
# no market access, no worker reallocation, no pollution transport
push!(options_in, (false, true, 0.0, false, false, false, true, false, false, false, true, false, tol))
# optimal
push!(options_in, (false, true, 0.0, true, true, true, true, false, true, false, true, false, tol))

# no worker reallocation
push!(options_in, (false, true, 0.0, false, true, true, true, false, false, false, true, false, tol))
# no market access effects
push!(options_in, (false, true, 0.0, true, true, false, true, false, false, false, true, false, tol))
# no pollution transport
push!(options_in, (false, true, 0.0, true, false, true, true, false, false, false, true, false, tol))


# ramping
push!(options_in, (true, true, 0.0, true, true, true, true, false, false, false, true, false, tol))

# ROBUSTNESS

# # optimal: no market access, no worker reallocation, no pollution transport
# # optimal: no worker reallocation
push!(options_in, (false, true, 0.0, false, false, false, true, false, true, false, true, false, tol))
push!(options_in, (false, true, 0.0, false, true, true, true, false, true, false, true, false, tol))

# production effects
push!(options_in, (false, true, 0.03, true, true, true, true, false, false, false, true, false, tol))
# production effects
push!(options_in, (false, true, -0.03, true, true, true, true, false, false, false, true, false, tol))
# congestion and agglomeration
push!(options_in, (false, true, 0.0, true, true, true, true, true, false, false, true, false, tol))
# income elastic VSL
push!(options_in, (false, true, 0.0, true, true, true, true, false, false, true, true, false, tol))

# ALTERNATIVE PARAMS

# trade elasticity
push!(options_in, (false, true, 0.0, true, true, true, true, false, false, false, true, false, tol, 4*2, .274*1, .481))
push!(options_in, (false, true, 0.0, true, true, true, true, false, false, false, true, false, tol, 4/2, .274*1, .481))

# labor share
push!(options_in, (false, true, 0.0, true, true, true, true, false, false, false, true, false, tol, 4*1, .274*1, 1))
push!(options_in, (false, true, 0.0, true, true, true, true, false, false, false, true, false, tol, 4*1, .274*1, .481/2))

# consumpton share
push!(options_in, (false, true, 0.0, true, true, true, true, false, false, false, true, false, tol, 4*1, .274*2, .481))
push!(options_in, (false, true, 0.0, true, true, true, true, false, false, false, true, false, tol, 4*1, .274/2, .481))

# migration elasticity
push!(options_in, (false, true, 0.0, true, true, true, true, false, false, false, true, false, tol, 4*1, .274, .481, 2.0))
push!(options_in, (false, true, 0.0, true, true, true, true, false, false, false, true, false, tol, 4*1, .274, .481, 0.495))

# pollution elasticities
push!(options_in, (false, true, 0.0, true, true, true, true, false, false, false, true, false, tol, 4*1, .274*1, .481, 1., 2))
push!(options_in, (false, true, 0.0, true, true, true, true, false, false, false, true, false, tol, 4*1, .274*1, .481, 1., 0.5))
push!(options_in, (false, true, 0.0, true, true, true, true, false, false, false, true, false, tol, 4*1, .274*1, .481, 1., 4))


@time pmap(
    (args) -> set_up_model(args...),
    options_in
    )